package VLine

import "VLine/Structure/List"

type Table struct {
	list    *List.List
	hashmap map[string]interface{}
	super   *Table
}

func TableNew(length ...int) *Table {
	if len(length) == 1 {
		return &Table{
			list:    List.New(length[0]),
			hashmap: make(map[string]interface{})}
	}
	return &Table{
		list:    List.New(),
		hashmap: make(map[string]interface{})}
}

func (table *Table) Clear() {
	table.list.Clear()
	table.hashmap = make(map[string]interface{})
}

func (table *Table) Put(key interface{}, value interface{}) {
	switch key := key.(type) {
	case float64:
		table.list.Set(int(key), value)
	case string:
		table.hashmap[key] = value
	}
}

func (table *Table) Get(key interface{}) interface{} {
	switch key := key.(type) {
	case float64:
		return table.list.Get(int(key))
	case string:
		return table.hashmap[key]
	}
	return nil
}

func (table *Table) Remove(key string) {
	delete(table.hashmap, key)
}
